-- with Ada.Real_Time;		use	Ada.Real_Time;

package body Ball_Package is

	-- corpo dell'oggetto protetto
	protected body Ball is

		-- F: field access
		
		procedure StopMoving is
			-- when Owner = 0 and Moving is
		begin
            if (Owner = 0 and Moving) then
				Moving := False;
            end if;
		end StopMoving;
		
		-- imposta il proprietario del pallone 
		procedure Control (ID : in Integer) is
			-- when Owner = 0 is
		begin
            if (Owner = 0) then
    			Owner := ID;
            end if;
		end Control;
		
		-- gestisce il movimento della palla
		procedure Movement is
			-- when Moving and Owner = 0 is
		begin
            if (Moving and Owner = 0) then
    			F.SetBallPosition(Step, Dir);
    			Power := Power - 1;
    			if (Power = 0) then
    				Moving := False;
    			end if;
            end if;
		end Movement;
			
		procedure Kick (D : in Integer; S : in Move; Pw : in Integer) is
			-- when Owner /= 0 is
		begin
            if (Owner /= 0) then
    			Owner := 0;
    			Dir := D;
    			Step := S;
    			Power := Pw;
    			Moving := True;
            end if;
		end Kick;
		
		-- ritorna il possessore della palla
		function GetOwner return Integer is
		begin
			return Owner;
		end GetOwner;
				
	end Ball;

end Ball_Package;
